<html>
	<head>
	  <title>three.js webgl - BVHLoader</title>
		<style>
			body {
				color: #fff;
				font-family:Monospace;
				font-size:13px;
				text-align:center;
				font-weight: bold;

				background-color: #000;
				margin: 0px;
				overflow: hidden;
			}

			#info {
				position: absolute;
				padding: 10px;
				width: 100%;
				text-align: center;
				color: #000000;
			}
		</style>

	</head>
	<body>
		<div id="info">
			<a href="http://threejs.org" target="_blank">three.js</a> - BVH Loader -
			animation from <a href="http://mocap.cs.cmu.edu/">http://mocap.cs.cmu.edu/</a>
		</div>
		<script src="../build/three.js"></script>
		<script src="js/controls/OrbitControls.js"></script>
		<script src="js/loaders/BVHLoader.js"></script>
		<script>

			var clock = new THREE.Clock();

			var camera, controls, scene, renderer;
			var mixer, skeletonHelper;

			init();
			animate();

			var loader = new THREE.BVHLoader();
			loader.load( "models/bvh/pirouette.bvh", function( result ) {

				skeletonHelper = new THREE.SkeletonHelper( result.skeleton.bones[ 0 ] );
				skeletonHelper.skeleton = result.skeleton; // allow animation mixer to bind to SkeletonHelper directly

				var boneContainer = new THREE.Group();
				boneContainer.add( result.skeleton.bones[ 0 ] );

				scene.add( skeletonHelper );
				scene.add( boneContainer );

				// play animation
				mixer = new THREE.AnimationMixer( skeletonHelper );
				mixer.clipAction( result.clip ).setEffectiveWeight( 1.0 ).play();

			} );

			function init() {

				camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
				camera.position.set( 0, 200, 400 );

				controls = new THREE.OrbitControls( camera );
				controls.minDistance = 300;
				controls.maxDistance = 700;

				scene = new THREE.Scene();

				scene.add( new THREE.GridHelper( 400, 10 ) );

				// renderer
				renderer = new THREE.WebGLRenderer( { antialias: true } );
				renderer.setClearColor( 0xeeeeee );
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );

				document.body.appendChild( renderer.domElement );

				window.addEventListener( 'resize', onWindowResize, false );

			}

			function onWindowResize() {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

				renderer.setSize( window.innerWidth, window.innerHeight );

			}

			function animate() {

				requestAnimationFrame( animate );

				var delta = clock.getDelta();

				if ( mixer ) mixer.update( delta );
				if ( skeletonHelper ) skeletonHelper.update();

				renderer.render( scene, camera );

			}

		</script>
	</body>
</html>
